//
//  HNSH_HomeNavView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/23.
//

#import "HNSH_HomeNavView.h"

@interface HNSH_HomeNavView ()
/** 搜索框灰色背景 */
@property (nonatomic, strong)UIView * grayBgView;
/** 搜索图片 */
@property (nonatomic, strong)UIImageView * searchImgView;
/**  */
@property (nonatomic, strong)UILabel * label;
/**  */
@property (nonatomic, strong)UILabel * searchLabel;

/* signButton */
@property (nonatomic, strong) UIButton *signButton;
/* newsButton */
@property (nonatomic, strong) UIButton *newsButton;
@end

@implementation HNSH_HomeNavView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addSubview:self.grayBgView];
    [self.grayBgView addSubview:self.searchImgView];
    [self.grayBgView addSubview:self.label];
    [self.grayBgView addSubview:self.searchLabel];
    [self addSubview:self.signButton];
    [self addSubview:self.newsButton];
    
    [self.grayBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(4+kStatusBarHeight);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-96);
        make.height.mas_equalTo(36);
    }];
    
    [self.searchImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.equalTo(self.grayBgView.mas_centerY);
        make.width.height.mas_equalTo(16);
    }];
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(36);
        make.centerY.equalTo(self.grayBgView.mas_centerY);
        make.height.mas_equalTo(20);
    }];
    
    
    
}

//MARK: 搜索
- (void)gesAction{
    if (self.searchBlock) {
        self.searchBlock();
    }
}

#pragma mark lazy
- (UIView *)grayBgView{
    if (!_grayBgView) {
        _grayBgView = [UIView new];
        _grayBgView.backgroundColor = [UIColor appWhiteLabelColor];
        _grayBgView.layer.cornerRadius = 18;
        _grayBgView.layer.masksToBounds = YES;
        
        UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesAction)];
        [_grayBgView addGestureRecognizer:ges];
    }
    return _grayBgView;
}

- (UIImageView *)searchImgView{
    if (!_searchImgView) {
        _searchImgView = [UIImageView new];
        _searchImgView.image = [UIImage imageNamed:@"home_nav_search_icon"];
    }
    return _searchImgView;
}

- (UILabel *)label{
    if (!_label) {
        _label = [UILabel new];
        _label.textColor = [UIColor colorWithHexString:@"#C3C3C3"];
        _label.font = [UIFont systemFontOfSize:14];
        _label.text = @"请输入商品名称/分类";
    }
    return _label;
}

- (UILabel *)searchLabel{
    if (!_searchLabel) {
        _searchLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth-108-60, 3, 56, 30)];
        _searchLabel.textColor = [UIColor appWhiteLabelColor];
        _searchLabel.font = [UIFont systemFontOfSize:14];
        _searchLabel.text = @"搜索";
        _searchLabel.textAlignment = NSTextAlignmentCenter;
        _searchLabel.backgroundColor = [UIColor due_colorGradientChangeWithSize:CGSizeMake(56, 30) direction:DUEGradientChangeDirectionLevel startColor:[UIColor colorWithHexString:@"#3EA700"] endColor:[UIColor colorWithHexString:@"#6AD335"]];;
        _searchLabel.layer.cornerRadius = 15.0f;
        _searchLabel.layer.masksToBounds = YES;
        
    }
    return _searchLabel;
}

- (UIButton *)signButton {
    if (!_signButton) {
        _signButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _signButton.frame = CGRectMake(kScreenWidth-88, kStatusBarHeight+2, 40, 40);
        [_signButton setImage:[UIImage imageNamed:@"home_nav_qiandao_icon"] forState:UIControlStateNormal];
        __weak __typeof(&*self)weakSelf = self;
        [[_signButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.signBlock) {
                weakSelf.signBlock();
            }
        }];
    }
    return _signButton;
}

- (UIButton *)newsButton {
    if (!_newsButton) {
        _newsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _newsButton.frame = CGRectMake(kScreenWidth-48, kStatusBarHeight+2, 40, 40);
        [_newsButton setImage:[UIImage imageNamed:@"home_nav_news_icon"] forState:UIControlStateNormal];
        __weak __typeof(&*self)weakSelf = self;
        [[_newsButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.newsBlock) {
                weakSelf.newsBlock();
            }
        }];
    }
    return _newsButton;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
